package com.nuoyuan.wx.service;

import com.nuoyuan.wx.common.aop.ProxyExceptionReturn;
import com.nuoyuan.wx.common.config.OssConfig;
import com.nuoyuan.wx.common.dto.BaseRespDto;
import com.nuoyuan.wx.common.utils.OssClientUtil;
import com.nuoyuan.wx.service.dto.FileDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * @Package com.nuoyuan.wx.service.respcode
 * @ClassName OssFileUploadServiceImpl
 * @Description TODO
 * @Author linus
 * @Date 2020-02-16 14:01
 * @Version 1.0
 **/
@Service
public class OssFileUploadServiceImpl {

    @Autowired
    private OssConfig ossConfig;

    @ProxyExceptionReturn
    public BaseRespDto uploadOSS(MultipartFile file, String fileName, String dir) throws Exception {
        String ossFileUrlBoot = OssClientUtil.upload(ossConfig, file, dir);
        FileDto fileDto = new FileDto();
        fileDto.setFileName(fileName);
        fileDto.setFileUrl(ossFileUrlBoot);

        BaseRespDto<FileDto> resp = BaseRespDto.buildSuccResp();
        resp.setData(fileDto);
        return resp;
    }
}
